<?php
namespace app\admin\controller;
use think\Controller;
use think\Session;
use think\captcha\Captcha;
use app\admin\model\Login as mLogin;

class Login extends Controller
{
    public function index()
    {
        Cfg();      //全局变量加载
        if(session('aid_admin.id')){
            $this->redirect('Index/index');
        }
        if (request()->isAjax()) {
            if(!captcha_check(input('post.captcha'))){
                $this->error('验证码有误');
            }else{
                $data = input('post.');

                if ($data['adminuser'] == false) {
                    $this->error('登录名不能为空');
                }
                if ($data['adminpassword'] == false) {
                    $this->error('登录密码不能为空');

                }

                $userStatus = mLogin::cheUsedStatus($data);
                return json($userStatus);
            }
        }

        return view();
    }

    public function code()
    {
        $config =    [
            // 验证码字体大小
            'fontSize'    =>    16,
            // 验证码位数
            'length'      =>    5,
            'fontttf'      =>   "4.ttf",
            // 关闭验证码杂点
            'useNoise'    =>    false,
            'useCurve'    =>    false,
            'useImgBg'    =>    false,
        ];
        $captcha = new Captcha($config);
        return $captcha->entry();
    }

    public function loUot(){

        if(session('aid_admin.id')){
            session('aid_admin',null);
            $this->success('退出成功',url('Login/index'));

        }
        $this->error('退出失败');

    }
}
